<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2017/3/11 0011
 * Time: 下午 11:59
 */
namespace api\controllers;

use yii\filters\AccessControl;
use yii\web\Request;
use Yii;
use yii\web\Response;
use common\helpers\StringHelper;

class IndexController extends \common\bases\BaseController
{
    public function init(){
        parent::init();
        $this->getResponse()->format = Response::FORMAT_JSON;
    }
    
    // 用户APP首页
    public function actionIndex()
    {
        $token   = $this->request->get('token','');
        $header_url = 'http://m.funfind.cn/user/wechat';
        $user_id = 0;
        $session_id = 0;
        if ($token) {
            $user_id = StringHelper::decrypt($token);
            if ($user_id) {
                $user_info = \api\models\User::findIdentity($user_id);
                if ($user_info) {
                    \Yii::$app->session['uid'] = $user_id;
                    // Yii::$app->user->login($user_info);
                    $session_id = Yii::$app->session->getId();
                    $header_url = 'http://web.funfind.cn/details/';
                }
            }
        }

        return [
            "code" => 0,
            "messgae" => "success",
            "data" => [
                'item'=>$header_url,
                "user_id" => $user_id,
                'PHPSESSID' => $session_id,
            ]
        ];
    }
}